import React, { useEffect, useState } from 'react'
import { Input, Button } from 'antd-mobile'

const Index: React.FC = () => {
	const [count, setCount] = useState(5)

	const curtDown = () => {
		setCount(count - 1)

		localStorage.setItem('token', '123')
	}

	useEffect(() => {
		if (count === 5) return
		
		if (count <= 0) {
			setCount(5)
		} else {
			setTimeout(() => {
				setCount(count - 1)
			}, 1000)
		}
	}, [count])

	return (
		<div>
			<Input placeholder=' 请输入手机号'></Input>
			<Button  disabled={ count !== 5} block color='primary' onClick={curtDown}>
				{count === 5 ? '获取验证码' : '距离倒计时结束还有' + count + 's'}</Button>
		</div>
	)
}


export default Index